<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        // 不设置过期 关闭浏览器后消失
        function setCokie(name, value, day = 0) {
            // 过期时间不是必传
            if (day != 0) {
                // 业务 expires
                var expires = day * 24 * 60 * 60 * 1000
                var date = new Date(+ new Date() + expires)
                console.log(date.toUTCString());
                document.cookie = `${name} = ${excape(value)};expire= ${date.toUTCString()}`
            } else {
                document.cookie = `${name}=${excape(value)}`;
            }
        }
        setCokie('name', 'age', 1)
    </script>
</body>

</html>